﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using YourFileWatcher.Models;

namespace YourFileWatcher.Converters
{

    /// <summary>
    /// 用户类型、布尔，绑定类型转换器（互相转化）
    /// </summary>
    [ValueConversion(typeof(UserType), typeof(bool?))]
    class UserTypeBoolConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            bool? result = null;

            UserType t = (UserType)value;
            if (t == UserType.Admin)
            {
                result = true;
            }
            if (t == UserType.User)
            {
                result = false;
            }
            return result;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            UserType result = UserType.User;

            bool? v = value as bool?;
            if (v == true)
            {
                result = UserType.Admin;
            }

            return result;
        }
    }
}
